package main

import (
	"fmt"
	"io"
	"log"
	"net"
)

var count int

func main() {
	listener, err := net.Listen("tcp", ":8001")

	if err != nil {
		log.Fatal(err)
	}

	var id int

	for {
		conn, err := listener.Accept()
		if err != nil {
			log.Print(err)
			continue
		}
		go handleConn(conn, id)
		id++
	}
}

func handleConn(c net.Conn, id int) {
	n, _ := io.Copy(c, c)
	conn := c.(*net.TCPConn)
	conn.Close()
	count++
	fmt.Printf("id:%d recv:%d bytes finish:%d\n", id, n, count)
}
